package com.sop.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sop.dao.PeopleDao;
import com.sop.model.PeopleInfo;
import com.sop.model.vo.PeopleInfoVo;
import com.sop.service.PeopleRoleService;
import com.sop.service.PeopleService;

import common.base.GridPage;
import common.base.service.BaseServiceImpl;

@Service("peopleService")
@Transactional
public class PeopleServiceImpl extends BaseServiceImpl<PeopleInfo,PeopleInfoVo> implements PeopleService{

	@Autowired
	private PeopleDao peopleDao;
	
	@Autowired
	private PeopleRoleService  peopleRoleService;

	@Resource(name="peopleDao")
	public void setBaseDao(PeopleDao  peopleDao){
		super.setBaseDao(peopleDao);
	}
	
	@Override
	public  List<PeopleInfo> getPeopleList() {
		List<PeopleInfo> list = peopleDao.getObjectALL();
		for(PeopleInfo peopleInfo:list){
			fill(peopleInfo);
		}
		return list;
	}

	@Override
	public PeopleInfo get(Integer id) {
		PeopleInfo peopleInfo = super.get(id);
		fill(peopleInfo);
		return peopleInfo;
	}
	
	
	private void fill(PeopleInfo peopleInfo) {
		peopleInfo.setRoleInfos(peopleRoleService.findRoleByPeoId(peopleInfo.getId()));
	}

	@Override
	public Boolean deleteBatch(List<Integer> ids) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PeopleInfo add(PeopleInfo entity) {
		peopleDao.save(entity);
		return get(entity.getId());
	}

	@Override
	public PeopleInfo update(PeopleInfo entity) {
		peopleDao.update(entity);
		return get(entity.getId());
	}


//	@Override
//	public GridPage<PeopleInfo> queryForPageInfo(PeopleInfoVo peopleInfoVo) {
//		int count = peopleDao.count(peopleInfoVo);  
//	      
//	    double dCount = (double)count;  
//	    double dRows = (double)peopleInfoVo.getRows();  
//	    int total = (int)Math.ceil(dCount / dRows); //total page   
//	    int curPage = Math.min(total, peopleInfoVo.getPage()); //current page   
//	    peopleInfoVo.setPage(curPage); //这是为了在dao中查询用的  
//	      
//	    List<PeopleInfo> list = peopleDao.queryForPageInfo(peopleInfoVo); 
//	    return new GridPage<PeopleInfo>(curPage,total,list.size(),list);
//	}

	
}
